package com.fouram.auth.controller;

import com.fouram.auth.form.LoginBo;
import com.fouram.auth.service.SysLoginService;
import com.fouram.core.domain.R;
import com.fouram.core.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * token 控制
 * 
 * @author fouram
 */
@Api(tags = "token接口")
@RestController
public class TokenController {

    @Autowired
    private TokenService tokenService;
    @Autowired
    private SysLoginService sysLoginService;

    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public R<?> login(@RequestBody LoginBo form) {
        String token = sysLoginService.login(form.getUsername(), form.getPassword());
        return R.ok(null, token);
    }

    @ApiOperation(value = "退出")
    @PostMapping("/logout")
    public R<?> logout() {
        tokenService.logout();
        return R.ok();
    }
}
